1 void fun(T)(T t) {
2 t.foobar;
3 }
4
5 auto m = mockStruct;
6 m.expect!"foobar";
7 fun(m);
8 m.verify;
1 void fun(T)(T t) {
2 t.foobar(2, "quux");
3 }
4
5 auto m = mockStruct;
6 m.expect!"foobar"(2, "quux");
7 fun(m);
8 m.verify;
1 int fun(T)(T f) {
2 return f.timesN(3) * 2;
3 }
4
5 auto m = mockStruct(42, 12);
6 assert(fun(m) == 84);
7 assert(fun(m) == 24);
8 assert(fun(m) == 0);
9 m.expectCalled!"timesN";
1 void fun(T)(T t) {
2 t.foobar(2, "quux");
3 }
4
5 auto m = mockStruct;
6 fun(m);
7 m.expectCalled!"foobar"(2, "quux");
1 auto m = mockStruct!(ReturnValues!("length", 5), ReturnValues!("greet", "hello"));
2 assert(m.length == 5);
3 assert(m.greet("bar") == "hello");
4 m.expectCalled!"length";
5 m.expectCalled!"greet"("bar");
1 auto m = mockStruct!(ReturnValues!("length", 5, 3), ReturnValues!("greet", "hello", "g'day"));
2 assert(m.length == 5);
3 m.expectCalled!"length";
4 assert(m.length == 3);
5 m.expectCalled!"length";
6
7 assert(m.greet("bar") == "hello");
8 m.expectCalled!"greet"("bar");
9 assert(m.greet("quux") == "g'day");
10 m.expectCalled!"greet"("quux");
Version of mockStruct that accepts a compile-time mapping of function name to return values. Each template parameter must be a value of type ReturnValues